<?php
namespace App\Utils\Other\PushOrder;

use App\Exception\InternalException;
use function Hyperf\Config\config;
use function Hyperf\Translation\__;

/**
 * 推单工具接口类
 * @author zx
 * @package other\pushorder
 */
Class PushOrder {

    /**
     * 配置
     * @var []
     */
    protected $config;

    public function __construct()
    {
        $this->setConfig();
    }

    /**
     * 设置配置
     * @return $this
     * @throws InternalException
     */
    protected function setConfig()
    {
        $this->config = config('cloud.push_order');
        if (!$this->config) {
            throw new InternalException(__('message.config.failed'));
        }
        return $this;
    }

    /**
     * 返回数据统一管理
     * @param $response
     * @return false|mixed
     */
    protected function response($response, $key='data')
    {
        if (!$response || !isset($response['code']) || $response['code'] !== '0') {
            return false;
        }
        return $key?$response[$key]:$response;
    }

    protected function getUrl($path)
    {
        return $this->config['url'].$path;
    }
}